<template>
  <a-layout-header
    :class="[
      fixHeader && 'ant-header-fixedHeader',
      layout === 'side' ? (sidebarOpened ? 'ant-header-side-opened' : 'ant-header-side-closed') : null,
      theme,
      'global-header'
    ]"
  >
    <div :class="['global-header-wide', layout]">
      <div class="main-logo" :style="{ width: mainLogoWidth }">
        <!-- <img src="static/img/company-title.png" alt="" @click="$router.push('/')" /> -->
        <h1 class="animated fadeIn">蓝得</h1>
       <!--  <h2 class="animated fadeIn">{{ companyNameEn }}</h2> -->
      </div>
      <!-- <router-link v-if="isMobile || layout === 'head'" to="/" :class="['logo', isMobile ? null : 'pc', theme]"> -->
      <div :class="['logo', isMobile ? null : 'pc', theme]">
        <!-- <img src="static/img/logo.png" alt="" /> -->
        <span class="system-name">{{ systemName }}</span>
        <!-- <br /> -->
        <!-- <span class="company-name">{{ systemNameEn }}</span> -->
      </div>
      <a-divider v-if="isMobile" type="vertical" />
      <!-- <a-icon
        v-if="layout === 'side'"
        class="trigger"
        :type="collapsed ? 'menu-unfold' : 'menu-fold'"
        @click="toggleCollapse"
      /> -->
      <div v-if="layout === 'head'" class="global-header-menu">
        <!-- style="height: 64px; line-height: 64px;" -->
        <i-menu class="system-top-menu" :theme="theme" mode="horizontal" :menuData="menuData" @select="onSelect" />
      </div>
      <div :class="['global-header-right', theme]">
        <header-avatar class="header-item" />
      </div>
    </div>
  </a-layout-header>
</template>

<script>
import HeaderAvatar from './HeaderAvatar';
import IMenu from '@/components/menu/menu';
import { mapState } from 'vuex';

export default {
  name: 'GlobalHeader',
  components: { IMenu, HeaderAvatar },
  props: ['collapsed', 'menuData'],
  data() {
    return {
      mainLogoWidth: (190 / 1366) * window.screen.width + 'px'
    };
  },
  computed: {
    ...mapState({
      isMobile: state => state.setting.isMobile,
      layout: state => state.setting.layout,
      systemName: state => state.setting.systemName,
      systemNameEn: state => state.setting.systemNameEn,
      sidebarOpened: state => state.setting.sidebar.opened,
      fixHeader: state => state.setting.fixHeader
    }),
    theme() {
      return this.layout === 'side' ? 'light' : this.$store.state.setting.theme;
    }
  },
  methods: {
    toggleCollapse() {
      this.$emit('toggleCollapse');
    },
    onSelect(obj) {
      this.$emit('menuSelect', obj);
    }
  }
};
</script>

<style lang="less" scoped>
@baseFontSize: 16;
@baseWidth: 1366;
.trigger {
  font-size: 20px;
  line-height: 64px;
  padding: 0 24px;
  cursor: pointer;
  transition: color 0.3s;
}
.header-item {
  padding: 0 19px;
  display: inline-block;
  height: 100%;
  cursor: pointer;
  vertical-align: middle;
  i {
    font-size: 16px;
    color: rgba(0, 0, 0, 0.65);
  }
}
.global-header {
  height: (54 / @baseFontSize) * 1rem !important;
  padding: 0 0 0 0;
  -webkit-box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  position: relative;
  &.light {
    background: #fff;
  }
  &.dark {
    background: #393e46;
  }
  .global-header-wide {
    .main-logo {
      display: inline-flex;
      background-color: #4675e7;
      // width: (190 / @baseWidth) * 100%;
      height: inherit;
      justify-content: center;
      align-items: center;
      img {
        // width: 88%;
        display: block;
        // padding-top: (13 / @baseFontSize) * 1rem;
        // vertical-align: middle;
      }
    }
    height: (54 / @baseFontSize) * 1rem;
    &.head {
      padding: 0 24px;
    }
    &.side {
      line-height: 0;
    }
    .logo {
      height: (54 / @baseFontSize) * 1rem;
      line-height: 100%;
      vertical-align: top;
      display: inline-flex;
      flex-direction: column;
      justify-content: center;
      // padding: 0 12px 0 24px;
      // cursor: pointer;
      font-size: 20px;
      padding-left: (30 / @baseFontSize) * 1rem;
      // padding-top: (13 / @baseFontSize) * 1rem;
      // padding-top: (10 / @baseFontSize) * 1rem;
      img {
        display: inline-block;
        vertical-align: middle;
        padding-right: 1vw;
        border-right: solid #fff 1px;
      }
      color: #fff;
      font-size: 8px;
      // display: inline-block;
      // line-height: 2vh;
      .system-name {
        color: #393d47;
        font-size: 17px;
        font-weight: bold;
        letter-spacing: (11.5 / @baseFontSize) * 1rem;
      }
      .company-name {
        color: #8799b0;
        font-family: Arial;
        position: relative;
        top: 6px;
      }

      &.pc {
        // padding: 0 12px 0 0;
        // padding-left: 2vw;
      }
      /* h1 {
        display: inline-block;
        font-size: 16px;
        color: #fff;
        padding-left: 0.5vw;
      }
      &.dark h1 {
        color: #fff;
      } */
    }
    .global-header-menu {
      display: inline-block;
    }
    .global-header-right {
      // float: right;
      display: inline-block;
      position: absolute;
      right: 0;
      height: (54 / @baseFontSize) * 1rem;
      &.dark {
        color: #fff;
        i {
          color: #fff;
        }
      }
    }
  }
}
.ant-header-fixedHeader {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 17;
  // width: (1176 / @baseWidth) * 100%;
  width: 100%;
  // padding-left: (190 / 1366) * 100vw;
  padding-left: 0;
  // padding-left: (190 / @baseFontSize) * 1rem;
  transition: width 0.2s;
  &.ant-header-side-opened {
    // width: (1176 / @baseWidth) * 100%;
    width: 100%;
    // padding-left: (190 / 1366) * 100%;
    padding-left: unset;
    // padding-left: (190 / @baseFontSize) * 1rem;
  }

  &.ant-header-side-closed {
    // width: (1176 / @baseWidth) * 100%;
    // width: 100%;
    padding-left: 80px;
  }
}
</style>
